/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pageBeans;

import controller.LoginControllerEJB;
import entities.Applicant;
import entities.Staff;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author Ant Ongun Kefeli
 */
@Named(value = "loginPageBean")
@SessionScoped
public class LoginPageBean implements Serializable {

    @EJB
    private LoginControllerEJB loginControllerEJB;
    @Inject
    private WizardPageBean wizardPageBean;
    private Applicant applicant = null;
    private Staff staff = null;
    private String email;
    private String password;
    private String error;

    public String login() {
        Applicant app = loginControllerEJB.loginApplicant(email, password);
        Staff staff = loginControllerEJB.loginStaff(email, password);
        String nextPage = null;
        if (app == null && staff == null) {//login error
            error = "Login failed";
            nextPage = "index";
        } else if (app != null) {
            error = "";
            this.applicant = app;
            wizardPageBean.applicantLogged();
            nextPage = "wizard";
        } else if (staff != null) {
            error = "";
            this.staff = staff;
            nextPage = "staff";
        }
        return nextPage;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public Applicant getApplicant() {
        return applicant;
    }

    public Staff getStaff() {
        return staff;
    }
    
    
}
